<?php
/**
* @package HelloWorld
* @version 1.0
* @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
* Joomla! is free software and parts of it may contain or be derived from the
* GNU General Public License or other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/

/** ensure this file is being included by a parent file */
defined( '_JEXEC' ) or die( 'Restricted access' );

/**
 * @package HelloWorld
 */
class HTML_ExtensionIcons {
/**  DEVNOTE: This class will take care of the actual display of pages for the component.
 *  It will be called by code in the admin.helloworld.php file.
 *  
 * Just a quick, 'global' note. Throughout these functions you will see calls to the static 'JText::_' function. 
 *  This function basically takes a parameter that is a 'description' of a string and will return the appropriate
 *  string for the user's current language. That is to say, by doing things this way, to localise a component you
 *   just have to create a language file for that language / component.

 * There is a language sub-directory in the administrator directory for the administrator components and a 
 * language sub-directory at the Joomla! root for 'front-end' components. 

 * Take for example the call:
 * JText::_( 'Weblink Manager' )

 * in the administrator/com_helloworld directory. Assuming the user's language is set as 'en-GB', this function will 
 * look in the administrator/language/en-GB directory for a file called 'en-GB.com_helloworld.ini'. Look in that
 * file and you will see rows of 'X=Y' types strings. In the example call above, 'HELLOWORLD' will be 'Hello World' 
 * (the parameter is converted to uppercase first) and the 'Y' value is what will be returned. Hence the example
 * function call will return 'Hello World'.

 * That may not seem so special as it stands, but this means that you can change strings fairly radically without
 * having to actually change your code AS WELL AS support different languages without having to change your code,
 * either. All you need do is create the appropriate language file. 
 */
   
   
   
	function listItems ($option, &$rows, &$pageNav )
	{
	   $number = count($rows);
	   global $mainframe;
	   
	   
	   		jimport('joomla.html.tooltips');
	/*   
echo "lang:".$mainframe->getCfg('lang');
echo '<hr />';
echo "live:".$mainframe->getCfg('live_site');
echo '<hr />';
echo JPATH_ADMINISTRATOR;
echo '<hr />';
*/
	echo '
      <script language="javascript" type="text/javascript">
         function submitbutton(pressbutton) {
           var form = document.adminForm;
           if (pressbutton == "cancel") {
              submitform( pressbutton );
              return;
           }
           submitform( pressbutton );
        }
     </script>';
     ?>
     <h2><img src="images/credits.png" alt="Hi" />Extension Icons</h2>
    <form action="index2.php" method="post" name="adminForm">
      <table class="adminlist">
      	<thead>
       <tr align="left">
        <th width="20">
         <input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count($rows); ?>);"/>
        </th>
        <th align="left" width="20"><?php echo JText::_('EXICONS_TIT_ICON'); ?></th>
        <th align="left"><?php echo JText::_('EXICONS_TIT_COMPONENT'); ?></th>
        <th align="left" colspan="2" width="40"><?php echo JText::_('EXICONS_TIT_SORT'); ?></th>
        <th align="center" width="20"><?php echo JText::_('EXICONS_TIT_PUBLISHED'); ?></th>
       </tr>'
      	</thead>
      	<tfoot>
      		<td colspan="13">
      		<?php	echo $pageNav->getListFooter(); ?>
			</td>
		</tfoot>
		<tbody>

<?php
        $cnt = 0;

		for ($i=0, $n=$number; $i < $n; $i++) {

			$row = &$rows[$i];

			$evenodd = $i % 2;

//    	    $task 	= $row->published ? 'unpublish' : 'publish';
//			$img 	= $row->published ? 'publish_g.png' : 'publish_x.png';
//			$alt 	= $row->published ? 'Published' : 'Unpublished';

			$checked 	= JCommonHTML::CheckedOutProcessing( $row, $i );//J1.5
			$published 	= JCommonHTML::PublishedProcessing( $row, $i );//J1.5

  			echo '
      <tr class="row'.$evenodd.'">
       <td>' . $checked . '</td>
       <td><img src="../includes/' . $row->admin_menu_img . '" /></td>
       <td>' .
       		'' .
       		'<span class="editlinktip hasTip" title="'. JText::_( 'Edit' ) . ': ' . $row->name .'">
					' .
       		'<strong>'.$row->parent_name.' </strong>'
        . '<a href="#edit" onclick="return listItemTask(\'cb'.$i.'\',\'edit\')">'
        .$row->name.'</a>
       </td>
      <td class="order" colspan="2">';
      
	echo $pageNav->orderUpIcon( $i, (@$row->catid == @$rows[$i-1]->catid) );
	echo $pageNav->orderDownIcon( $i, $n, (@$row->catid == @$rows[$i+1]->catid) );

	echo '</td>';
	echo '<td align="center">';

	echo $published;
	
    //echo '<a href="javascript: void(0);" onclick="return listItemTask(\'cb'. $i .'\',\'' . $task . '\')">
	//	<img src="images/' . $img . '" width="12" height="12" border="0" alt="' . $alt . '" /></a>';
    
    echo '</td></tr>';

    }//fornext


	echo '' .
			'</tbody>
  	 </table>
      <input type="hidden" name="option"
             value="'.$option.'" />
      <input type="hidden" name="task" value="" />
      <input type="hidden" name="boxchecked" value="0" />
     </form>';
     }//function	
     
  function edit( $option, &$row )
  {
global $mosConfig_live_site, $mosConfig_absolute_path, $mosConfig_lang;
//mosCommonHTML::loadOverlib();
jimport('joomla.html.tooltips');

/*
if (file_exists('administrator/components/com_extensionicons/language/'.$mosConfig_lang.'.php')) {
	require_once ('administrator/components/com_extensionicons/language/'.$mosConfig_lang.'.php');
} else {
	require_once ('administrator/components/com_extensionicons/language/english.php');
}
*/
  ?>

  <script language="javascript" type="text/javascript">
        function submitbutton(pressbutton) {
           var form = document.adminForm;
           if (pressbutton == "cancel") {
              submitform( pressbutton );
              return;
           }
           submitform( pressbutton );
        }
     </script>
     <?php
echo '<form action="index2.php" method="post"
        name="adminForm" id="adminForm" class="adminForm">';

echo '<table class="adminheading">'
		. '<tr><th>'.JText::_('EXICONS_TIT_EDIT').': <small>';
if ($row->name)
{
	echo $row->parent_name;
	if ($row->parent_name) echo ' - ';
	echo $row->name;
	echo ' <img src="../includes/' . $row->admin_menu_img . '" />';
} else
{
	echo JText::_('_EXICONS_NEW_ITEM');
}
	echo '</small></th>'
		. '</tr></table>';

echo '<table class="adminform">';

/*
 * List Icons in /includes/js/ThemeOffice
 */
echo '<tr valign="top">'
 		. '<td style="text-align:right">'
// 		.'<img src="'.$mosConfig_live_site . '/includes/' . $row->admin_menu_img . '" />
		
		.'<span class="editlinktip hasTip" title="'.JText::_('_EXICONS_TOO_ICON').'"><strong>'.JText::_('_EXICONS_TIT_ICON').':</strong></span>'
 		//. mostooltip( _EXICONS_TOO_ICON ) .
		.'</td>'
 		.'<td>';// .

$Pfad = '../includes/js/ThemeOffice/';
$sPfad = '../includes/js/ThemeOffice/';
$DD = dir($Pfad);
$icon_count = 0;
$icon_max   = 5;
echo '<table><tr><td>';
while (false !== ($entry = $DD->read()))
{
     if($entry != '.' && $entry != '..'
     	&& substr ($entry, strlen ($entry) -3) == 'png'
     	&& $entry != 'spacer.png'
     	&& $entry != 'blank.png')
     {
        echo '<label><input type="radio" name="admin_menu_img" value="js/ThemeOffice/' . $entry . '"';
       	if ('js/ThemeOffice/' . $entry == $row->admin_menu_img)
       	{
       		echo 'checked="checked"';
       	}
        echo		' />';
        echo '<img src="'.$sPfad . $entry . '" />';
		echo '</label><br /><br />';
		$icon_count += 1;
     }
     if ( $icon_count == $icon_max )
     {
     	echo '</td><td>';
     	$icon_count = 0;
     }
}//while
echo '</td></tr>'
. '</table>';

/*
 * List images in custom_dir /images/exicons
 */
$Pfad = '../images/ExtensionIcons_custom/';
$sPfad = '/images/ExtensionIcons_custom/';

echo '<tr valign="top">'.
 		'<td style="text-align:right">' .
 		'<span class="editlinktip hasTip" title="'.JText::_('EXICONS_TOO_ICON_PATH' ) .'">'.
		'<strong>'.JText::_('EXICONS_TIT_ICON_PATH').':</strong>'.
 		'<br />' .
 		$Pfad.
		'</span>'.
// 		.'<img src="'.$mosConfig_live_site . '/includes/' . $row->admin_menu_img . '" />
		'</td>'.
 		'<td>';// .
echo '<table><tr><td>';

if (is_dir($Pfad))
{
	$DD = dir($Pfad);
	$icon_count = 0;
	$iconTotal = 0;
	$icon_max   = 5;//number of icons to display: down
	while (false !== ($entry = $DD->read()))
	{
     	if($entry != '.' && $entry != '..'
	     	&& substr ($entry, strlen ($entry) -3) == 'png'
     		&& $entry != 'spacer.png'
     		&& $entry != 'blank.png')
     	{
	        echo '<label><input type="radio" name="admin_menu_img" value="'.$Pfad . $entry . '"';
       		if ( $Pfad . $entry == $row->admin_menu_img )
       		{
	       		echo 'checked="checked"';
       		}
        	echo		' />';
        	echo '<img src="'.$mosConfig_live_site . $sPfad . $entry . '" />';
			echo '</label><br /><br />';
			$icon_count += 1;
			$iconTotal+=1;
     	}
     	if ( $icon_count == $icon_max )
     	{
	     	echo '</td><td>';
     		$icon_count = 0;
     	}
  	}//while
  	if ( $iconTotal == 0 )
  	{
  		echo JText::_('EXICONS_NO_FILES_IN_DIR');
  	}
} else
{
	echo JText::_('EXICONS_DIR_NO_EXISTS');
}//if is_dir

echo '</td></tr>' .
	'</table>';

echo '<tr><td colspan="2"><hr /></td></tr>';

echo
		'</td>' .
		'</tr>';

echo	'<tr><td style="text-align:right">' .
		'<span class="editlinktip hasTip" title="'.JText::_('EXICONS_TOO_NAME' ) .'">' .
		'<strong>' . JText::_('EXICONS_TIT_NAME') . ' :</strong><br />'.
		'</span>'.
		'</td><td><input type="text" name="name" value="' .
		 $row->name . '" />' .
		 '</td></tr>';

echo	'<tr><td style="text-align:right">' .
		'<strong>' . JText::_('EXICONS_TIT_MENUALT') . ' :</strong><br />'.
		'<span class="editlinktip hasTip" title="'.JText::_('EXICONS_TOO_MENUALT' ) .'"></span>'.
		'</td><td><input type="text" name="admin_menu_alt" value="' .
		 $row->admin_menu_alt . '" />' .
		 '</td></tr>';

echo	'<tr><td style="text-align:right">' .
		'<strong>' . JText::_('EXICONS_TIT_OPTION') . ' :</strong><br />'.
		'<span class="editlinktip hasTip" title="'.JText::_('EXICONS_TOO_OPTION' ) .'">'.
		'</td><td><input type="text" name="linkoption" value="' .
		 $row->linkoption . '" />' .
		 '</td></tr>';

echo	'<tr><td style="text-align:right">' .
		'<strong>' . JText::_('EXICONS_TIT_MENULINK') . ' :</strong><br />'.
		'<span class="editlinktip hasTip" title="'.JText::_('EXICONS_TOO_MENULINK' ) .'">'.
		'</td><td><input type="text" name="admin_menu_link" size="50" value="' .
		 $row->admin_menu_link . '" />' .
		 '</td></tr>';

//echo 	'<tr><td colspan="2"><hr /></td></tr>'
echo 	'<tr>'
			. '<td style="text-align:right"><strong>'.JText::_('EXICONS_TIT_PUBLISHED').':</strong></td>'
			. '<td>'
			. JHTMLSelect::yesnoList( 'published', 'class="inputbox"', $row->published )
			. '</td>'
		. '</tr>';

echo 	'</table>';

echo	'<input type="hidden" name="id" value="' . $row->id . '" />
	    <input type="hidden" name="option" value="' . $option . '" />
   		<input type="hidden" name="task" value="" />
   </form>';
 }//function

 function help ( $option , $AppVersion )
 {
 global $mosConfig_absolute_path, $mosConfig_lang;

	if (file_exists ($mosConfig_absolute_path.'/administrator/components/com_extensionicons/language/help_'.$mosConfig_lang.'.php'))
	{
		require_once ($mosConfig_absolute_path.'/administrator/components/com_extensionicons/language/help_'.$mosConfig_lang.'.php');
	} else
	{
		require_once ($mosConfig_absolute_path.'/administrator/components/com_extensionicons/language/help_english.php');
	}
	HTML_ExtensionIcons::printFooter( $AppVersion );
 }     

 function printFooter ( $AppVersion )
 {
	echo '<div class="smallgrey">' . $AppVersion . ' - ' . JText::_('EXICONS_GREETZ_NIK') . ' <a href="http://www.nik-it.de">NiK-IT.de</a></div>';
 }//function
	
	function helloworld()
	 {
	  //get text string based on languages
	  $ret = JText::_('helloworld'); 
	  
/** DEVNOTE: Joomla offers system log capabilities.
 *  Let's see what we're gonna see in logs/error.log
 *  This might be extremely usefull for debuging your code
 */ 
    //we will need joomla log system     
	  jimport( 'joomla.utilities.log' );
	  //give me log object
    $log = & JLog::getInstance();
    // write variable int log
    $log->addEntry(array("level" => 0,"status"=> 1, "comment" => "helloworld :".$ret));
	  //print string
	  echo $ret;
   }

	function helloagain()
	 {
	  //get text string based on languages
	  $ret = JText::_('helloagain'); 
	  
	  //log information
	  jimport( 'joomla.utilities.log' );
    $log = & JLog::getInstance();
    $log->addEntry(array("level" => 0,"status"=> 1, "comment" => "helloagain :".$ret));
	 
	  //print string
	  echo $ret;
   }   
   
	function hellotestfoo()
	 {
	  //get text string based on languages
	  $ret = JText::_('hellotestfoo'); 
	  
	  //log information
	  jimport( 'joomla.utilities.log' );
    $log = & JLog::getInstance();
    $log->addEntry(array("level" => 0,"status"=> 1, "comment" => "hellotestfoo :".$ret));
	 
	  //print string
	  echo $ret;
   }   

	function hellodefault()
	 {
	  //get text string based on languages
	  $ret = JText::_('hellodefault'); 
	  
	  //log information
	  jimport( 'joomla.utilities.log' );
    $log = & JLog::getInstance();
    $log->addEntry(array("level" => 0,"status"=> 1, "comment" => "hellodefault :".$ret));
	 
	  //print string
	  echo $ret;
   }  
       
}
?>
